
package com.benimetum.program;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

/**
 *
 * @author Ethem Cem Ozkan
 * @email ethemcem.ozkan@gmail.com
 * No 07110604
 */
public class CourseProgram
{
    public static String getCourseProgram(String studentId){  
    String result="";
    try {
		// ogrencino=07110604&btn_ogrenci=Program%FD+G%F6ster&dd_ders=2015874&sube=0&dd_derslik=57&dd_hoca=2183470&dd_bolum=9&dd_sinif=1
		String data =null;
		data += "&" + URLEncoder.encode("ogrencino", "UTF-8") + "=" + URLEncoder.encode(studentId, "UTF-8");
		data += "&" + URLEncoder.encode("sube", "UTF-8") + "=" + URLEncoder.encode("0", "UTF-8");
		data += "&" + URLEncoder.encode("btn_ogrenci", "UTF-8") + "=" + URLEncoder.encode("Program%FD+G%F6ster", "UTF-8");
		URL url = new URL("http://kayit.etu.edu.tr/Ders/Ders_prg.php");
		URLConnection conn = url.openConnection();
		conn.setDoOutput(true);
		OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
		wr.write(data);
		wr.flush();
		// Get the response
		BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		String line;
		while ((line = rd.readLine()) != null) {
		    result+=line;
		}
		wr.close();
		rd.close();
	  } 
	  catch (Exception e) {
	  }
    return result;
    }
    
    public static String getFinalProgram(String studentId){  
    String result="";
    try {
		// ogrencino=07110604&btn_ogrenci=Program%FD+G%F6ster&dd_ders=2015874&sube=0&dd_derslik=57&dd_hoca=2183470&dd_bolum=9&dd_sinif=1
		String data =null;
		data += "&" + URLEncoder.encode("ogrencino", "UTF-8") + "=" + URLEncoder.encode(studentId, "UTF-8");
		data += "&" + URLEncoder.encode("sube", "UTF-8") + "=" + URLEncoder.encode("0", "UTF-8");
		data += "&" + URLEncoder.encode("btn_ogrenci", "UTF-8") + "=" + URLEncoder.encode("Program%FD+G%F6ster", "UTF-8");
                URL url = new URL("http://kayit.etu.edu.tr/final/Final_prg.php");
		URLConnection conn = url.openConnection();
                conn.setRequestProperty("Accept-Charset", "UTF-8");
		conn.setDoOutput(true);
		OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
		wr.write(data);
		wr.flush();
		// Get the response
		BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		String line;
		while ((line = rd.readLine()) != null) {
		    result+=line;
		}
		wr.close();
		rd.close();
	  } 
	  catch (Exception e) {
	  }
    return result;
    }
}
